home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue54
/
Alfresco
/
TstCrypU.pas
< prev
Wrap
Pascal/Delphi Source File
|
1999-12-12
|
3KB
|
130 lines
unit TstCrypU;
interface
uses
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, AACrypt;
type
TForm1 = class(TForm)
mOriginal: TMemo;
mEncrypted: TMemo;
mDecrypted: TMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
RadioGroup1: TRadioGroup;
edtKey: TEdit;
Label4: TLabel;
edtCaesarShift: TEdit;
Label5: TLabel;
Button1: TButton;
procedure RadioGroup1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
SubstTable : TaaADFGVXTable;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex = 0 then begin
edtCaesarShift.Enabled := true;
edtKey.Enabled := false;
end
else begin
edtCaesarShift.Enabled := false;
edtKey.Enabled := true;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
OrigStm : TMemoryStream;
EncryptStm : TMemoryStream;
DecryptStm : TMemoryStream;
Shift : integer;
ec : integer;
i : integer;
XORKey : PByteArray;
begin
OrigStm := nil;
EncryptStm := nil;
DecryptStm := nil;
try
OrigStm := TMemoryStream.Create;
EncryptStm := TMemoryStream.Create;
DecryptStm := TMemoryStream.Create;
mOriginal.Lines.SaveToStream(OrigStm);
case RadioGroup1.ItemIndex of
0 : begin
Val(edtCaesarShift.Text, Shift, ec);
if (ec <> 0) then
Shift := 3;
OrigStm.Position := 0;
AACaesarCipher(true, Shift, OrigStm, EncryptStm);
EncryptStm.Position := 0;
AACaesarCipher(false, Shift, EncryptStm, DecryptStm);
end;
1 : begin
OrigStm.Position := 0;
AAVigenereCipher(true, edtKey.Text, OrigStm, EncryptStm);
EncryptStm.Position := 0;
AAVigenereCipher(false, edtKey.Text, EncryptStm, DecryptStm);
end;
2 : begin
OrigStm.Position := 0;
AAADFGVXCipher(true, edtKey.Text, SubstTable,
OrigStm, EncryptStm);
EncryptStm.Position := 0;
AAADFGVXCipher(false, edtKey.Text, SubstTable,
EncryptStm, DecryptStm);
end;
3 : begin
GetMem(XORKey, length(edtKey.Text));
try
for i := 1 to length(edtKey.Text) do
XORKey^[i-1] := ord(edtKey.Text[i]);
OrigStm.Position := 0;
AAXORCipher(XORKey, length(edtKey.Text),
OrigStm, EncryptStm);
EncryptStm.Position := 0;
AAXORCipher(XORKey, length(edtKey.Text),
EncryptStm, DecryptStm);
finally
FreeMem(XORKey, length(edtKey.Text));
end;
end;
end;
EncryptStm.Position := 0;
mEncrypted.Lines.LoadFromStream(EncryptStm);
DecryptStm.Position := 0;
mDecrypted.Lines.LoadFromStream(DecryptStm);
finally
OrigStm.Free;
EncryptStm.Free;
DecryptStm.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SubstTable := AAGenADFGVXTable;
end;
end.